package com.douqu.game.auth.web.request;

import com.douqu.game.core.database.model.OrderRecordModel;
import com.douqu.game.core.e.E_RechargeStatus;
import com.douqu.game.core.factory.ConstantFactory;
import com.douqu.game.core.util.LogUtils;
import com.douqu.game.core.web.request.RechargeParam;

import java.util.Map;

/**
* @author wangzhenfei
*         2018-01-17 16:38
*/
public class AliCheckOrderReqParam {
    private final String TRADE_SUCCESS = "TRADE_SUCCESS";

    private String gmt_create;
    private String charset;
    private String seller_email;
    private String subject;
    private String sign;
    private String body;
    private String buyer_id;
    private String invoice_amount;
    private String notify_id;
    private String fund_bill_list;
    private String notify_type;
    private String trade_status;
    private String receipt_amount;
    private String app_id;
    private String buyer_pay_amount;
    private String sign_type;
    private String seller_id;
    private String gmt_payment;
    private String notify_time;
    private String passback_params;
    private String version;
    private String out_trade_no;
    private String total_amount;
    private String trade_no;
    private String auth_app_id;
    private String buyer_logon_id;
    private String point_amount;


    private RechargeParam innerParam;

    public AliCheckOrderReqParam(Map<String, String> map){
        if(map == null){
            LogUtils.debug("支付宝回调参数map为空" );
            return;
        }
        LogUtils.debug("支付宝回调参数:" + map.toString());
        passback_params = map.get("passback_params");
        trade_no = map.get("trade_no");
        total_amount = map.get("total_amount");
        trade_status = map.get("trade_status");


    }

    public String getTrade_no() {
        return trade_no;
    }

    public boolean isSuccess(){
        return TRADE_SUCCESS.equals(trade_status);
    }

    public RechargeParam getInnerParam() {
        if(innerParam == null){
            innerParam = new RechargeParam(passback_params);
//            innerParam = JsonUtils.fromJSON(YjInnerParam.class, cbi);
        }
        return innerParam;
    }

    public int getFee() {
        return (int)(Float.valueOf(total_amount) * 100);
    }

    public String getPassback_params() {
        return passback_params;
    }

    public OrderRecordModel getOrderRecordModel(String paymentType){
        RechargeParam params =  getInnerParam();
        return new OrderRecordModel(params.getObjectIndex(), params.getObjectIndex(),
                trade_no, trade_no, paymentType, getFee(), params.getRechargeId(), params.getServerId(),params.getOutTradeNo(),
                params.getLv(),params.getDiamonds(),params.getRuleId(),paymentType, E_RechargeStatus.PAY_SUCCESS);
    }

}
